package com.jcli.jb51_net.article._129493_分割窗口控件;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

/**
 * @author li
 * @version 1.0
 * @belongsProject novel_20230923
 * @belongsPackage com.jcli.jb51_net.article._129493_分割窗口控件
 * @className MainFrame
 * @description TODO  分割窗口
 * @createTime 2024-01-23  21:29
 */
public class MainFrame extends JFrame {
    JSplitPane jSplitPane = new JSplitPane();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    private static final long serialVersionUID = 1L;

    public static void main(String[] args) {
//        https://www.jb51.net/article/34175.htm
//Java Swing 非常漂亮外观Nimbus的使用方法实例
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }
        new MainFrame();
    }

    public MainFrame() {

        jbInit();
        myInit();
    }

    private void myInit() {

//        设定关闭窗口后自动退出进程
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设定窗口默认尺寸
        this.setSize(800, 600);
        //    设定窗体状态为屏幕最大化，即全屏尺寸
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        //    显示窗体
        this.setVisible(true);
        //    设定分割面板左右比例，防止在setVisible之前则无效
        this.jSplitPane.setDividerLocation(0.7);
        this.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                jSplitPane.setDividerLocation(0.7);
            }
        });
    }

    private void jbInit() {
        this.getContentPane().add(jSplitPane, BorderLayout.CENTER);
        jSplitPane.add(jPanel1, JSplitPane.LEFT);
        jSplitPane.add(jPanel2, JSplitPane.RIGHT);
        //固定
        jSplitPane.setEnabled(false);
        //设置一触式可扩展
        jSplitPane.setOneTouchExpandable(true);
    }
}
